import { HTTP } from "../util/http-p.js";

class IndexModel extends HTTP {
  typeList(softLevel=0) {
    let user_info = this._getUserData();
    return this.request({
      url: "index/typeList",
      method: "GET",
      data: {
        token: user_info.token,
        softLevel:softLevel
      }
    });
  }

  indexUserDta(isSet,typeId=0){
    let user_info = this._getUserData();
    if(user_info==""){
        return -1;
    }
    if(typeId==0){
        typeId=user_info.selTypeId; 
    }
    user_info.selTypeId=typeId;
    wx.setStorageSync('web_user_info', user_info);
    return this.request({
        url: "index/indexUserData",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:typeId,
          isSet:isSet
        }
      });
  }

  setExamTime(examTime){
    let user_info = this._getUserData();
    return this.request({
        url: "index/setExamTime",
        method: "POST",
        data: {
          token: user_info.token,
          examTime:examTime
        }
      });
  }

  getQuestionList(dataSource,typeId,page){
    let user_info = this._getUserData();
    return this.request({
        url: "index/getQuestions",
        method: "POST",
        data: {
          token: user_info.token,
          dataSource:dataSource,
          typeId:typeId,
          page:page
        }
      });
  }

  resetDoProgress(dataSource,typeId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/resetDoProgress",
        method: "POST",
        data: {
          token: user_info.token,
          dataSource:dataSource,
          typeId:typeId
        }
      });
  }

  doQuestions(sourceType,typeId,courseId,userAnswer,questionId,indexNum){
    let user_info = this._getUserData();
    return this.request({
        url: "index/doQuestions",
        method: "POST",
        data: {
          token: user_info.token,
          dataSource:sourceType,
          typeId:typeId,
          userAnswer:userAnswer,
          questionId:questionId,
          indexNum:indexNum,
          courseId:courseId
        }
      });
  }

  collQuestion(questionId,isCollect,dataType,typeId,courseId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/questionCollect",
        method: "POST",
        data: {
          token: user_info.token,
          questionId:questionId,
          isCollect:isCollect,
          dataType:dataType,
          typeId:typeId,
          courseId:courseId
        }
      });
  }

  correctSubmit(questionId,feedBackMsg){
    let user_info = this._getUserData();
    return this.request({
        url: "index/correctSubmit",
        method: "POST",
        data: {
          token: user_info.token,
          questionId:questionId,
          feedBackMsg:feedBackMsg
        }
      });
  }

  noteSubmit(questionId,typeId,courseId,dataSource,noteMsg){
    let user_info = this._getUserData();
    return this.request({
        url: "index/noteSubmit",
        method: "POST",
        data: {
          token: user_info.token,
          questionId:questionId,
          typeId:typeId,
          dataSource:dataSource,
          noteMsg:noteMsg,
          courseId:courseId
        }
      });
  }

  answerRecords(sourceType,typeId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/answerRecords",
        method: "POST",
        data: {
          token: user_info.token,
          dataSource:sourceType,
          typeId:typeId
        }
      });
  }

  getPastYear(courseId,yearType){
    let user_info = this._getUserData();
    return this.request({
        url: "index/getPastYear",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId,
          yearType:yearType
        }
      });
  }

  getErrorList(courseId,errorType=0){
    let user_info = this._getUserData();
    return this.request({
        url: "index/getErrorList",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId,
          errorType:errorType
        }
      });
  }

  getCollectList(courseId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/getCollectList",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId
        }
      });
  }
  getNoteList(courseId,page){
    let user_info = this._getUserData();
    return this.request({
        url: "index/getNoteList",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId,
          page:page
        }
      });
  }
  delNote(noteId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/delNote",
        method: "POST",
        data: {
          token: user_info.token,
          noteId:noteId
        }
      });
  }

  updateNote(noteId,noteMsg){
    let user_info = this._getUserData();
    return this.request({
        url: "index/updateNote",
        method: "POST",
        data: {
          token: user_info.token,
          noteId:noteId,
          noteMsg:noteMsg
        }
      });
  }

  userExamRecord(courseId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/userExamRecord",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId
        }
      });
  }

  mockExamQuestions(courseId,mockId,page){
    let user_info = this._getUserData();
    return this.request({
        url: "index/mockExamQuestions",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId,
          mockId:mockId,
          page:page
        }
      });
  }

  examTimeIngSave(remainingTime,courseId,mockId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/examTimeIngSave",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId,
          mockId:mockId,
          remainingTime:remainingTime
        }
      });
  }
  examDone(rightNum,mockId,courseId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/examDone",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId,
          mockId:mockId,
          rightNum:rightNum
        }
      });
  }

  mockList(courseId){
    let user_info = this._getUserData();
    return this.request({
        url: "index/mockList",
        method: "POST",
        data: {
          token: user_info.token,
          courseId:courseId
        }
      });
  }

  errorRemoveSetting(times){
    let user_info = this._getUserData();
    user_info.right_times=times;
    wx.setStorageSync('web_user_info', user_info);
    return this.request({
        url: "index/errorRemoveSetting",
        method: "POST",
        data: {
          token: user_info.token,
          times:times
        }
      });
  }
  infoSubmit(nickname,userphone){
    let user_info = this._getUserData();
    user_info.user_phone=userphone;
    user_info.nick_name=nickname;
    wx.setStorageSync('web_user_info', user_info);
    return this.request({
        url: "index/infoSubmit",
        method: "POST",
        data: {
          token: user_info.token,
          nickName:nickname,
          userPhone:userphone
        }
      });
  }

  //获取用户信息
  _getUserData() {
    let user_info = wx.getStorageSync('web_user_info');
    return user_info;
  }

}

export { IndexModel };
